package cn.lg.soar.flow.biz.entity;

import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.database.base.entity.BaseEntity;
import cn.lg.soar.flow.api.model.node.ButtonInfo;
import cn.lg.soar.flow.api.model.node.FieldInfo;
import cn.lg.soar.flow.api.model.node.Node;
import cn.lg.soar.flow.api.model.node.ProcessListener;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 流程定义
 * @author luguoxiang
 * @since 2025-08-02
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Data
@Schema(description = "流程定义")
@TableName(value = "lg_flow_process", autoResultMap = true)
public class SoarProcess extends BaseEntity {

    /** 主键 */
    @NotNull(message = "主键不能为空", groups = { Update.class })
    @ExcelIgnore
    @Schema(description = "主键")
    @TableId
    private Long id;

    /** 编码 */
    @NotBlank(message = "编码不能为空", groups = { Create.class, Update.class })
    @ExcelProperty(value = "编码")
    @Schema(description = "编码")
    private String code;

    /** 名称 */
    @NotBlank(message = "名称不能为空", groups = { Create.class, Update.class })
    @ExcelProperty(value = "名称")
    @Schema(description = "名称")
    private String name;

    /** logo */
    @ExcelProperty(value = "logo")
    @Schema(description = "logo")
    private String logo;

    /** 标题模板 */
    @ExcelProperty(value = "标题模板")
    @Schema(description = "标题模板")
    private String titleTemplate;

    /** 是否禁用（0否，1是） */
    @ExcelProperty(value = "是否禁用（0否，1是）")
    @Schema(description = "是否禁用（0否，1是）")
    private Boolean disabled;

    /** 字段信息 */
    @Schema(description = "字段信息")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<FieldInfo> fields;

    /** 按钮信息 */
    @Schema(description = "按钮信息")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<ButtonInfo> buttons;

    /** 监听器 */
    @Schema(description = "监听器")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<ProcessListener> listeners;

    /** 节点信息 */
    @Schema(description = "节点信息")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<Node> nodes;

    /** 部署版本id */
    @Schema(description = "部署版本id")
    private String versionId;

    /** 最后一次部署时间 */
    @Schema(description = "最后一次部署时间")
    private LocalDateTime lastDeployTime;

    @JsonIgnore
    @Override
    public Long primaryKey() {
        return this.id;
    }

}
